package javacode.chapter04;

public class Example4_10 {
    public static void main(String[] args) {
        // 计算1~100中所有偶数的和
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                sum += i;
            }
        }
        System.out.println("1~100中所有偶数的和是：" + sum);

        sum = 0;
        for (int i = 2; i <= 100; i += 2) {
            sum += i;
        }
        System.out.println("1~100中所有偶数的和是：" + sum);
    }
}
